{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "60990d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pandas import Series,DataFrame\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e31a98da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "4    5\n",
       "5    6\n",
       "dtype: int64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Series(data=[1,2,3,4,5,6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "45ada361",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    81\n",
       "1    94\n",
       "2    69\n",
       "3    43\n",
       "4    98\n",
       "5    36\n",
       "6     5\n",
       "7    52\n",
       "8    56\n",
       "9    44\n",
       "dtype: int32"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Series(data=np.random.randint(0,100,size=(10,)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ebd3a9c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "语文    150\n",
      "数学    150\n",
      "英语    150\n",
      "理综    300\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "s1 = Series(data=[150,150,150,300],index=['语文','数学','英语','理综'])\n",
    "print(s1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d746d95e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "150 数学    150\n",
      "英语    150\n",
      "理综    300\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(s1[1],s1['数学':\"理综\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "00ccacf3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "语文    150\n",
       "数学    150\n",
       "英语    150\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "fd54ee8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 12,  3, 32,  2,  5, 23,  4, 42,  6], dtype=int64)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Series([1,12,1,1,1,1,3,32,2,5,3,2,3,23,23,2,4,4,42,2,2,6])\n",
    "s.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "405bb4d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    2.0\n",
       "b    NaN\n",
       "c    6.0\n",
       "d    NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = Series([1,2,3],index=['a','b','c'])\n",
    "s3 = Series([1,2,3],index=['a','d','c'])\n",
    "s4 = s2 + s3\n",
    "s4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a9ceb4a2",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    2.0\n",
       "c    6.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s4[[1,2]]\n",
    "s4[[True,False,True,False]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "144934ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    False\n",
       "b     True\n",
       "c    False\n",
       "d     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s4.isnull()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3de5c705",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    2.0\n",
       "c    6.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s4[s4.notnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9302283c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>11</td>\n",
       "      <td>96</td>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>46</td>\n",
       "      <td>73</td>\n",
       "      <td>50</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>41</td>\n",
       "      <td>55</td>\n",
       "      <td>99</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D\n",
       "a  11  96   7  76\n",
       "b  46  73  50  93\n",
       "c  41  55  99  39"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(data=np.random.randint(0,100,size=(3,4)),index=['a','b','c'],columns=['A','B','C','D'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7c91fa6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['A', 'B', 'C', 'D'], dtype='object')\n",
      "[[11 96  7 76]\n",
      " [46 73 50 93]\n",
      " [41 55 99 39]]\n",
      "Index(['a', 'b', 'c'], dtype='object')\n",
      "(3, 4)\n"
     ]
    }
   ],
   "source": [
    "print(df.columns,df.values,df.index,df.shape,sep='\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d1def516",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四\n",
       "语文  150   0\n",
       "数学  150   0\n",
       "英语  150   0\n",
       "理综  150   0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = DataFrame(data=[[150,0],[150,0],[150,0],[150,0]],index=['语文','数学','英语','理综'],columns=['张三','李四'])\n",
    "dic={\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0]\n",
    "    \n",
    "}\n",
    "df2 = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b1136a6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "语文    150\n",
       "数学    150\n",
       "英语    150\n",
       "理综    150\n",
       "Name: 张三, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2['张三']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "66bc45c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>李四</th>\n",
       "      <th>张三</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    李四   张三\n",
       "语文   0  150\n",
       "数学   0  150\n",
       "英语   0  150\n",
       "理综   0  150"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2[['李四','张三']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "39889014",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "张三    150\n",
       "李四      0\n",
       "Name: 语文, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.loc['语文']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f506cbe6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    11\n",
       "B    96\n",
       "C     7\n",
       "D    76\n",
       "Name: a, dtype: int32"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "30aefd8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "150"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2['张三']['英语']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cbd596eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "150"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.loc['英语','张三']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "5b907c9a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "数学    150\n",
       "理综    150\n",
       "Name: 张三, dtype: int64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.loc[['数学','理综'],'张三']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f9a1121e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三\n",
       "语文  150\n",
       "数学  150\n",
       "英语  150\n",
       "理综  150"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.iloc[:,0:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d572bbd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "qizhong = df2\n",
    "qimo=df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b436ce55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四\n",
       "语文  150   0\n",
       "数学  150   0\n",
       "英语  150   0\n",
       "理综  150   0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "cb90c9c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四\n",
       "语文  150   0\n",
       "数学  150   0\n",
       "英语  150   0\n",
       "理综  150   0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qimo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f981d2cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       张三   李四\n",
       "语文  150.0  0.0\n",
       "数学  150.0  0.0\n",
       "英语  150.0  0.0\n",
       "理综  150.0  0.0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(qizhong+qimo)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "2e06f1e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "qizhong.loc['数学','张三'] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "80efef7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四\n",
       "语文  150   0\n",
       "数学    0   0\n",
       "英语  150   0\n",
       "理综  150   0"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "d5a78d73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三   李四\n",
       "语文  150  100\n",
       "数学    0  100\n",
       "英语  150  100\n",
       "理综  150  100"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong['李四'] += 100\n",
    "qizhong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "bb75b0d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>10</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三   李四\n",
       "语文  160  110\n",
       "数学   10  110\n",
       "英语  160  110\n",
       "理综  160  110"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong += 10\n",
    "qizhong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f677448a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240719</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240718</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240717</td>\n",
       "      <td>1476.10</td>\n",
       "      <td>1503.00</td>\n",
       "      <td>1470.02</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>25.40</td>\n",
       "      <td>1.7209</td>\n",
       "      <td>34311.01</td>\n",
       "      <td>5115680.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240716</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1482.00</td>\n",
       "      <td>1465.05</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.0746</td>\n",
       "      <td>20316.44</td>\n",
       "      <td>2998367.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240715</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1488.00</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1478.82</td>\n",
       "      <td>-3.92</td>\n",
       "      <td>-0.2651</td>\n",
       "      <td>19176.26</td>\n",
       "      <td>2835374.730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5476</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010831</td>\n",
       "      <td>37.15</td>\n",
       "      <td>37.62</td>\n",
       "      <td>36.80</td>\n",
       "      <td>37.01</td>\n",
       "      <td>37.10</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>-0.2400</td>\n",
       "      <td>23231.48</td>\n",
       "      <td>86231.237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5477</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010830</td>\n",
       "      <td>36.28</td>\n",
       "      <td>37.51</td>\n",
       "      <td>36.00</td>\n",
       "      <td>37.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>0.72</td>\n",
       "      <td>1.9800</td>\n",
       "      <td>48013.06</td>\n",
       "      <td>177558.558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5478</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010829</td>\n",
       "      <td>36.98</td>\n",
       "      <td>37.00</td>\n",
       "      <td>36.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>36.86</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-1.3000</td>\n",
       "      <td>53252.75</td>\n",
       "      <td>194689.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5479</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010828</td>\n",
       "      <td>34.99</td>\n",
       "      <td>37.00</td>\n",
       "      <td>34.61</td>\n",
       "      <td>36.86</td>\n",
       "      <td>35.55</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3.6900</td>\n",
       "      <td>129647.79</td>\n",
       "      <td>463463.143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5480</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010827</td>\n",
       "      <td>34.51</td>\n",
       "      <td>37.78</td>\n",
       "      <td>32.85</td>\n",
       "      <td>35.55</td>\n",
       "      <td>31.39</td>\n",
       "      <td>4.16</td>\n",
       "      <td>13.2500</td>\n",
       "      <td>406318.00</td>\n",
       "      <td>1410347.179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5481 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code trade_date     open     high      low    close  pre_close  \\\n",
       "0     600519.SH   20240719  1490.81  1529.18  1484.01  1525.62    1497.51   \n",
       "1     600519.SH   20240718  1499.50  1515.00  1492.53  1497.51    1501.40   \n",
       "2     600519.SH   20240717  1476.10  1503.00  1470.02  1501.40    1476.00   \n",
       "3     600519.SH   20240716  1476.00  1482.00  1465.05  1476.00    1474.90   \n",
       "4     600519.SH   20240715  1470.00  1488.00  1470.00  1474.90    1478.82   \n",
       "...         ...        ...      ...      ...      ...      ...        ...   \n",
       "5476  600519.SH   20010831    37.15    37.62    36.80    37.01      37.10   \n",
       "5477  600519.SH   20010830    36.28    37.51    36.00    37.10      36.38   \n",
       "5478  600519.SH   20010829    36.98    37.00    36.10    36.38      36.86   \n",
       "5479  600519.SH   20010828    34.99    37.00    34.61    36.86      35.55   \n",
       "5480  600519.SH   20010827    34.51    37.78    32.85    35.55      31.39   \n",
       "\n",
       "      change  pct_chg        vol       amount  \n",
       "0      28.11   1.8771   38942.91  5888615.145  \n",
       "1      -3.89  -0.2591   28870.39  4337214.601  \n",
       "2      25.40   1.7209   34311.01  5115680.654  \n",
       "3       1.10   0.0746   20316.44  2998367.128  \n",
       "4      -3.92  -0.2651   19176.26  2835374.730  \n",
       "...      ...      ...        ...          ...  \n",
       "5476   -0.09  -0.2400   23231.48    86231.237  \n",
       "5477    0.72   1.9800   48013.06   177558.558  \n",
       "5478   -0.48  -1.3000   53252.75   194689.620  \n",
       "5479    1.31   3.6900  129647.79   463463.143  \n",
       "5480    4.16  13.2500  406318.00  1410347.179  \n",
       "\n",
       "[5481 rows x 11 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tushare as ts\n",
    "ts.set_token('f82cb78fa05ce47842ad5fdd6038749d831f28d8bd13157e242dbe5c')\n",
    "pro = ts.pro_api()\n",
    "df = pro.daily(ts_code='600519.SH',start_data='19000101')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7f0976e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('./maotai.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "30beda3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240719</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240718</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240717</td>\n",
       "      <td>1476.10</td>\n",
       "      <td>1503.00</td>\n",
       "      <td>1470.02</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>25.40</td>\n",
       "      <td>1.7209</td>\n",
       "      <td>34311.01</td>\n",
       "      <td>5115680.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240716</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1482.00</td>\n",
       "      <td>1465.05</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.0746</td>\n",
       "      <td>20316.44</td>\n",
       "      <td>2998367.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240715</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1488.00</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1478.82</td>\n",
       "      <td>-3.92</td>\n",
       "      <td>-0.2651</td>\n",
       "      <td>19176.26</td>\n",
       "      <td>2835374.730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5476</th>\n",
       "      <td>5476</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010831</td>\n",
       "      <td>37.15</td>\n",
       "      <td>37.62</td>\n",
       "      <td>36.80</td>\n",
       "      <td>37.01</td>\n",
       "      <td>37.10</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>-0.2400</td>\n",
       "      <td>23231.48</td>\n",
       "      <td>86231.237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5477</th>\n",
       "      <td>5477</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010830</td>\n",
       "      <td>36.28</td>\n",
       "      <td>37.51</td>\n",
       "      <td>36.00</td>\n",
       "      <td>37.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>0.72</td>\n",
       "      <td>1.9800</td>\n",
       "      <td>48013.06</td>\n",
       "      <td>177558.558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5478</th>\n",
       "      <td>5478</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010829</td>\n",
       "      <td>36.98</td>\n",
       "      <td>37.00</td>\n",
       "      <td>36.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>36.86</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-1.3000</td>\n",
       "      <td>53252.75</td>\n",
       "      <td>194689.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5479</th>\n",
       "      <td>5479</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010828</td>\n",
       "      <td>34.99</td>\n",
       "      <td>37.00</td>\n",
       "      <td>34.61</td>\n",
       "      <td>36.86</td>\n",
       "      <td>35.55</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3.6900</td>\n",
       "      <td>129647.79</td>\n",
       "      <td>463463.143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5480</th>\n",
       "      <td>5480</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010827</td>\n",
       "      <td>34.51</td>\n",
       "      <td>37.78</td>\n",
       "      <td>32.85</td>\n",
       "      <td>35.55</td>\n",
       "      <td>31.39</td>\n",
       "      <td>4.16</td>\n",
       "      <td>13.2500</td>\n",
       "      <td>406318.00</td>\n",
       "      <td>1410347.179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5481 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0    ts_code  trade_date     open     high      low    close  \\\n",
       "0              0  600519.SH    20240719  1490.81  1529.18  1484.01  1525.62   \n",
       "1              1  600519.SH    20240718  1499.50  1515.00  1492.53  1497.51   \n",
       "2              2  600519.SH    20240717  1476.10  1503.00  1470.02  1501.40   \n",
       "3              3  600519.SH    20240716  1476.00  1482.00  1465.05  1476.00   \n",
       "4              4  600519.SH    20240715  1470.00  1488.00  1470.00  1474.90   \n",
       "...          ...        ...         ...      ...      ...      ...      ...   \n",
       "5476        5476  600519.SH    20010831    37.15    37.62    36.80    37.01   \n",
       "5477        5477  600519.SH    20010830    36.28    37.51    36.00    37.10   \n",
       "5478        5478  600519.SH    20010829    36.98    37.00    36.10    36.38   \n",
       "5479        5479  600519.SH    20010828    34.99    37.00    34.61    36.86   \n",
       "5480        5480  600519.SH    20010827    34.51    37.78    32.85    35.55   \n",
       "\n",
       "      pre_close  change  pct_chg        vol       amount  \n",
       "0       1497.51   28.11   1.8771   38942.91  5888615.145  \n",
       "1       1501.40   -3.89  -0.2591   28870.39  4337214.601  \n",
       "2       1476.00   25.40   1.7209   34311.01  5115680.654  \n",
       "3       1474.90    1.10   0.0746   20316.44  2998367.128  \n",
       "4       1478.82   -3.92  -0.2651   19176.26  2835374.730  \n",
       "...         ...     ...      ...        ...          ...  \n",
       "5476      37.10   -0.09  -0.2400   23231.48    86231.237  \n",
       "5477      36.38    0.72   1.9800   48013.06   177558.558  \n",
       "5478      36.86   -0.48  -1.3000   53252.75   194689.620  \n",
       "5479      35.55    1.31   3.6900  129647.79   463463.143  \n",
       "5480      31.39    4.16  13.2500  406318.00  1410347.179  \n",
       "\n",
       "[5481 rows x 12 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./maotai.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "479bfb8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop(labels=('Unnamed: 0'),axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7a33a2bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240719</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240718</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240717</td>\n",
       "      <td>1476.10</td>\n",
       "      <td>1503.00</td>\n",
       "      <td>1470.02</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>25.40</td>\n",
       "      <td>1.7209</td>\n",
       "      <td>34311.01</td>\n",
       "      <td>5115680.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240716</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1482.00</td>\n",
       "      <td>1465.05</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.0746</td>\n",
       "      <td>20316.44</td>\n",
       "      <td>2998367.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240715</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1488.00</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1478.82</td>\n",
       "      <td>-3.92</td>\n",
       "      <td>-0.2651</td>\n",
       "      <td>19176.26</td>\n",
       "      <td>2835374.730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5476</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010831</td>\n",
       "      <td>37.15</td>\n",
       "      <td>37.62</td>\n",
       "      <td>36.80</td>\n",
       "      <td>37.01</td>\n",
       "      <td>37.10</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>-0.2400</td>\n",
       "      <td>23231.48</td>\n",
       "      <td>86231.237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5477</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010830</td>\n",
       "      <td>36.28</td>\n",
       "      <td>37.51</td>\n",
       "      <td>36.00</td>\n",
       "      <td>37.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>0.72</td>\n",
       "      <td>1.9800</td>\n",
       "      <td>48013.06</td>\n",
       "      <td>177558.558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5478</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010829</td>\n",
       "      <td>36.98</td>\n",
       "      <td>37.00</td>\n",
       "      <td>36.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>36.86</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-1.3000</td>\n",
       "      <td>53252.75</td>\n",
       "      <td>194689.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5479</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010828</td>\n",
       "      <td>34.99</td>\n",
       "      <td>37.00</td>\n",
       "      <td>34.61</td>\n",
       "      <td>36.86</td>\n",
       "      <td>35.55</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3.6900</td>\n",
       "      <td>129647.79</td>\n",
       "      <td>463463.143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5480</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20010827</td>\n",
       "      <td>34.51</td>\n",
       "      <td>37.78</td>\n",
       "      <td>32.85</td>\n",
       "      <td>35.55</td>\n",
       "      <td>31.39</td>\n",
       "      <td>4.16</td>\n",
       "      <td>13.2500</td>\n",
       "      <td>406318.00</td>\n",
       "      <td>1410347.179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5481 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code  trade_date     open     high      low    close  pre_close  \\\n",
       "0     600519.SH    20240719  1490.81  1529.18  1484.01  1525.62    1497.51   \n",
       "1     600519.SH    20240718  1499.50  1515.00  1492.53  1497.51    1501.40   \n",
       "2     600519.SH    20240717  1476.10  1503.00  1470.02  1501.40    1476.00   \n",
       "3     600519.SH    20240716  1476.00  1482.00  1465.05  1476.00    1474.90   \n",
       "4     600519.SH    20240715  1470.00  1488.00  1470.00  1474.90    1478.82   \n",
       "...         ...         ...      ...      ...      ...      ...        ...   \n",
       "5476  600519.SH    20010831    37.15    37.62    36.80    37.01      37.10   \n",
       "5477  600519.SH    20010830    36.28    37.51    36.00    37.10      36.38   \n",
       "5478  600519.SH    20010829    36.98    37.00    36.10    36.38      36.86   \n",
       "5479  600519.SH    20010828    34.99    37.00    34.61    36.86      35.55   \n",
       "5480  600519.SH    20010827    34.51    37.78    32.85    35.55      31.39   \n",
       "\n",
       "      change  pct_chg        vol       amount  \n",
       "0      28.11   1.8771   38942.91  5888615.145  \n",
       "1      -3.89  -0.2591   28870.39  4337214.601  \n",
       "2      25.40   1.7209   34311.01  5115680.654  \n",
       "3       1.10   0.0746   20316.44  2998367.128  \n",
       "4      -3.92  -0.2651   19176.26  2835374.730  \n",
       "...      ...      ...        ...          ...  \n",
       "5476   -0.09  -0.2400   23231.48    86231.237  \n",
       "5477    0.72   1.9800   48013.06   177558.558  \n",
       "5478   -0.48  -1.3000   53252.75   194689.620  \n",
       "5479    1.31   3.6900  129647.79   463463.143  \n",
       "5480    4.16  13.2500  406318.00  1410347.179  \n",
       "\n",
       "[5481 rows x 11 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "91148928",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'trade_date'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "File \u001b[1;32mC:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3653\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3652\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 3653\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3654\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
      "File \u001b[1;32mC:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\_libs\\index.pyx:147\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mC:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\_libs\\index.pyx:176\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7080\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7088\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'trade_date'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[44], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mtype\u001b[39m(df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtrade_date\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;241m9\u001b[39m])\n",
      "File \u001b[1;32mC:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\core\\frame.py:3761\u001b[0m, in \u001b[0;36mDataFrame.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3759\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mnlevels \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m   3760\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_getitem_multilevel(key)\n\u001b[1;32m-> 3761\u001b[0m indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mget_loc(key)\n\u001b[0;32m   3762\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[0;32m   3763\u001b[0m     indexer \u001b[38;5;241m=\u001b[39m [indexer]\n",
      "File \u001b[1;32mC:\\ProgramData\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3655\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3653\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3654\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m-> 3655\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m   3656\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m   3657\u001b[0m     \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[0;32m   3658\u001b[0m     \u001b[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[0;32m   3659\u001b[0m     \u001b[38;5;66;03m#  the TypeError.\u001b[39;00m\n\u001b[0;32m   3660\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n",
      "\u001b[1;31mKeyError\u001b[0m: 'trade_date'"
     ]
    }
   ],
   "source": [
    "type(df['trade_date'][9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0506e520",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240719</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20240718</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code  trade_date     open     high      low    close  pre_close  \\\n",
       "0  600519.SH    20240719  1490.81  1529.18  1484.01  1525.62    1497.51   \n",
       "1  600519.SH    20240718  1499.50  1515.00  1492.53  1497.51    1501.40   \n",
       "\n",
       "   change  pct_chg       vol       amount  \n",
       "0   28.11   1.8771  38942.91  5888615.145  \n",
       "1   -3.89  -0.2591  28870.39  4337214.601  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "86d8bcdf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2024-07-19</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-18</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-17</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1476.10</td>\n",
       "      <td>1503.00</td>\n",
       "      <td>1470.02</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>25.40</td>\n",
       "      <td>1.7209</td>\n",
       "      <td>34311.01</td>\n",
       "      <td>5115680.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-16</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1482.00</td>\n",
       "      <td>1465.05</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.0746</td>\n",
       "      <td>20316.44</td>\n",
       "      <td>2998367.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-15</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1488.00</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1478.82</td>\n",
       "      <td>-3.92</td>\n",
       "      <td>-0.2651</td>\n",
       "      <td>19176.26</td>\n",
       "      <td>2835374.730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-31</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>37.15</td>\n",
       "      <td>37.62</td>\n",
       "      <td>36.80</td>\n",
       "      <td>37.01</td>\n",
       "      <td>37.10</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>-0.2400</td>\n",
       "      <td>23231.48</td>\n",
       "      <td>86231.237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-30</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>36.28</td>\n",
       "      <td>37.51</td>\n",
       "      <td>36.00</td>\n",
       "      <td>37.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>0.72</td>\n",
       "      <td>1.9800</td>\n",
       "      <td>48013.06</td>\n",
       "      <td>177558.558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-29</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>36.98</td>\n",
       "      <td>37.00</td>\n",
       "      <td>36.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>36.86</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-1.3000</td>\n",
       "      <td>53252.75</td>\n",
       "      <td>194689.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-28</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>34.99</td>\n",
       "      <td>37.00</td>\n",
       "      <td>34.61</td>\n",
       "      <td>36.86</td>\n",
       "      <td>35.55</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3.6900</td>\n",
       "      <td>129647.79</td>\n",
       "      <td>463463.143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-27</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>34.51</td>\n",
       "      <td>37.78</td>\n",
       "      <td>32.85</td>\n",
       "      <td>35.55</td>\n",
       "      <td>31.39</td>\n",
       "      <td>4.16</td>\n",
       "      <td>13.2500</td>\n",
       "      <td>406318.00</td>\n",
       "      <td>1410347.179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5481 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              ts_code     open     high      low    close  pre_close  change  \\\n",
       "trade_date                                                                     \n",
       "2024-07-19  600519.SH  1490.81  1529.18  1484.01  1525.62    1497.51   28.11   \n",
       "2024-07-18  600519.SH  1499.50  1515.00  1492.53  1497.51    1501.40   -3.89   \n",
       "2024-07-17  600519.SH  1476.10  1503.00  1470.02  1501.40    1476.00   25.40   \n",
       "2024-07-16  600519.SH  1476.00  1482.00  1465.05  1476.00    1474.90    1.10   \n",
       "2024-07-15  600519.SH  1470.00  1488.00  1470.00  1474.90    1478.82   -3.92   \n",
       "...               ...      ...      ...      ...      ...        ...     ...   \n",
       "2001-08-31  600519.SH    37.15    37.62    36.80    37.01      37.10   -0.09   \n",
       "2001-08-30  600519.SH    36.28    37.51    36.00    37.10      36.38    0.72   \n",
       "2001-08-29  600519.SH    36.98    37.00    36.10    36.38      36.86   -0.48   \n",
       "2001-08-28  600519.SH    34.99    37.00    34.61    36.86      35.55    1.31   \n",
       "2001-08-27  600519.SH    34.51    37.78    32.85    35.55      31.39    4.16   \n",
       "\n",
       "            pct_chg        vol       amount  \n",
       "trade_date                                   \n",
       "2024-07-19   1.8771   38942.91  5888615.145  \n",
       "2024-07-18  -0.2591   28870.39  4337214.601  \n",
       "2024-07-17   1.7209   34311.01  5115680.654  \n",
       "2024-07-16   0.0746   20316.44  2998367.128  \n",
       "2024-07-15  -0.2651   19176.26  2835374.730  \n",
       "...             ...        ...          ...  \n",
       "2001-08-31  -0.2400   23231.48    86231.237  \n",
       "2001-08-30   1.9800   48013.06   177558.558  \n",
       "2001-08-29  -1.3000   53252.75   194689.620  \n",
       "2001-08-28   3.6900  129647.79   463463.143  \n",
       "2001-08-27  13.2500  406318.00  1410347.179  \n",
       "\n",
       "[5481 rows x 10 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./maotai.csv',index_col='trade_date',parse_dates=['trade_date'])\n",
    "df.drop(labels=('Unnamed: 0'),axis=1,inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "93cca7f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2024-07-12 00:00:00')"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3c40b864",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2024-07-19</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1490.81</td>\n",
       "      <td>1529.18</td>\n",
       "      <td>1484.01</td>\n",
       "      <td>1525.62</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>28.11</td>\n",
       "      <td>1.8771</td>\n",
       "      <td>38942.91</td>\n",
       "      <td>5888615.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-18</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1499.50</td>\n",
       "      <td>1515.00</td>\n",
       "      <td>1492.53</td>\n",
       "      <td>1497.51</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>-3.89</td>\n",
       "      <td>-0.2591</td>\n",
       "      <td>28870.39</td>\n",
       "      <td>4337214.601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-17</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1476.10</td>\n",
       "      <td>1503.00</td>\n",
       "      <td>1470.02</td>\n",
       "      <td>1501.40</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>25.40</td>\n",
       "      <td>1.7209</td>\n",
       "      <td>34311.01</td>\n",
       "      <td>5115680.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-16</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1482.00</td>\n",
       "      <td>1465.05</td>\n",
       "      <td>1476.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.0746</td>\n",
       "      <td>20316.44</td>\n",
       "      <td>2998367.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-15</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1488.00</td>\n",
       "      <td>1470.00</td>\n",
       "      <td>1474.90</td>\n",
       "      <td>1478.82</td>\n",
       "      <td>-3.92</td>\n",
       "      <td>-0.2651</td>\n",
       "      <td>19176.26</td>\n",
       "      <td>2835374.730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-31</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>37.15</td>\n",
       "      <td>37.62</td>\n",
       "      <td>36.80</td>\n",
       "      <td>37.01</td>\n",
       "      <td>37.10</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>-0.2400</td>\n",
       "      <td>23231.48</td>\n",
       "      <td>86231.237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-30</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>36.28</td>\n",
       "      <td>37.51</td>\n",
       "      <td>36.00</td>\n",
       "      <td>37.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>0.72</td>\n",
       "      <td>1.9800</td>\n",
       "      <td>48013.06</td>\n",
       "      <td>177558.558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-29</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>36.98</td>\n",
       "      <td>37.00</td>\n",
       "      <td>36.10</td>\n",
       "      <td>36.38</td>\n",
       "      <td>36.86</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-1.3000</td>\n",
       "      <td>53252.75</td>\n",
       "      <td>194689.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-28</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>34.99</td>\n",
       "      <td>37.00</td>\n",
       "      <td>34.61</td>\n",
       "      <td>36.86</td>\n",
       "      <td>35.55</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3.6900</td>\n",
       "      <td>129647.79</td>\n",
       "      <td>463463.143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-08-27</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>34.51</td>\n",
       "      <td>37.78</td>\n",
       "      <td>32.85</td>\n",
       "      <td>35.55</td>\n",
       "      <td>31.39</td>\n",
       "      <td>4.16</td>\n",
       "      <td>13.2500</td>\n",
       "      <td>406318.00</td>\n",
       "      <td>1410347.179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5481 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              ts_code     open     high      low    close  pre_close  change  \\\n",
       "trade_date                                                                     \n",
       "2024-07-19  600519.SH  1490.81  1529.18  1484.01  1525.62    1497.51   28.11   \n",
       "2024-07-18  600519.SH  1499.50  1515.00  1492.53  1497.51    1501.40   -3.89   \n",
       "2024-07-17  600519.SH  1476.10  1503.00  1470.02  1501.40    1476.00   25.40   \n",
       "2024-07-16  600519.SH  1476.00  1482.00  1465.05  1476.00    1474.90    1.10   \n",
       "2024-07-15  600519.SH  1470.00  1488.00  1470.00  1474.90    1478.82   -3.92   \n",
       "...               ...      ...      ...      ...      ...        ...     ...   \n",
       "2001-08-31  600519.SH    37.15    37.62    36.80    37.01      37.10   -0.09   \n",
       "2001-08-30  600519.SH    36.28    37.51    36.00    37.10      36.38    0.72   \n",
       "2001-08-29  600519.SH    36.98    37.00    36.10    36.38      36.86   -0.48   \n",
       "2001-08-28  600519.SH    34.99    37.00    34.61    36.86      35.55    1.31   \n",
       "2001-08-27  600519.SH    34.51    37.78    32.85    35.55      31.39    4.16   \n",
       "\n",
       "            pct_chg        vol       amount  \n",
       "trade_date                                   \n",
       "2024-07-19   1.8771   38942.91  5888615.145  \n",
       "2024-07-18  -0.2591   28870.39  4337214.601  \n",
       "2024-07-17   1.7209   34311.01  5115680.654  \n",
       "2024-07-16   0.0746   20316.44  2998367.128  \n",
       "2024-07-15  -0.2651   19176.26  2835374.730  \n",
       "...             ...        ...          ...  \n",
       "2001-08-31  -0.2400   23231.48    86231.237  \n",
       "2001-08-30   1.9800   48013.06   177558.558  \n",
       "2001-08-29  -1.3000   53252.75   194689.620  \n",
       "2001-08-28   3.6900  129647.79   463463.143  \n",
       "2001-08-27  13.2500  406318.00  1410347.179  \n",
       "\n",
       "[5481 rows x 10 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e80f5bee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2024-07-02', '2024-06-24', '2024-03-12', '2024-02-21',\n",
       "               '2023-12-28', '2023-07-28', '2023-05-22', '2023-01-05',\n",
       "               '2022-11-15', '2022-11-04',\n",
       "               ...\n",
       "               '2004-01-14', '2004-01-05', '2003-10-29', '2003-01-14',\n",
       "               '2002-01-31', '2002-01-18', '2001-12-21', '2001-09-10',\n",
       "               '2001-08-28', '2001-08-27'],\n",
       "              dtype='datetime64[ns]', name='trade_date', length=356, freq=None)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df['close']*0.03 > df['open']*0.03)\n",
    "\n",
    "df.loc[(df['close']-df['open'])/df['open']>0.03].index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "7d9ed21e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2001-08-27        NaN\n",
       "2001-08-28      35.55\n",
       "2001-08-29      36.86\n",
       "2001-08-30      36.38\n",
       "2001-08-31      37.10\n",
       "               ...   \n",
       "2024-07-15    1478.82\n",
       "2024-07-16    1474.90\n",
       "2024-07-17    1476.00\n",
       "2024-07-18    1501.40\n",
       "2024-07-19    1497.51\n",
       "Name: close, Length: 5481, dtype: float64"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[(df['open']-df['pre_close'])/df['pre_close'] < -0.02].index\n",
    "df['close'].shift(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "b436d2bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>change</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>open</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>ts_code</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>753405.635</td>\n",
       "      <td>0.12</td>\n",
       "      <td>169.94</td>\n",
       "      <td>172.00</td>\n",
       "      <td>169.31</td>\n",
       "      <td>172.00</td>\n",
       "      <td>0.07</td>\n",
       "      <td>169.82</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>44304.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>535720.422</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>169.44</td>\n",
       "      <td>171.50</td>\n",
       "      <td>169.00</td>\n",
       "      <td>170.99</td>\n",
       "      <td>-0.29</td>\n",
       "      <td>169.94</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>31513.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>666073.283</td>\n",
       "      <td>-2.68</td>\n",
       "      <td>166.76</td>\n",
       "      <td>169.50</td>\n",
       "      <td>166.31</td>\n",
       "      <td>168.99</td>\n",
       "      <td>-1.58</td>\n",
       "      <td>169.44</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>39889.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>801445.269</td>\n",
       "      <td>-3.04</td>\n",
       "      <td>163.72</td>\n",
       "      <td>167.19</td>\n",
       "      <td>161.88</td>\n",
       "      <td>166.76</td>\n",
       "      <td>-1.82</td>\n",
       "      <td>166.76</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>48825.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>593162.176</td>\n",
       "      <td>-1.72</td>\n",
       "      <td>162.00</td>\n",
       "      <td>164.00</td>\n",
       "      <td>160.10</td>\n",
       "      <td>164.00</td>\n",
       "      <td>-1.05</td>\n",
       "      <td>163.72</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>36702.09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                amount  change   close    high     low    open  pct_chg  \\\n",
       "trade_date                                                                \n",
       "2010-01-04  753405.635    0.12  169.94  172.00  169.31  172.00     0.07   \n",
       "2010-01-05  535720.422   -0.50  169.44  171.50  169.00  170.99    -0.29   \n",
       "2010-01-06  666073.283   -2.68  166.76  169.50  166.31  168.99    -1.58   \n",
       "2010-01-07  801445.269   -3.04  163.72  167.19  161.88  166.76    -1.82   \n",
       "2010-01-08  593162.176   -1.72  162.00  164.00  160.10  164.00    -1.05   \n",
       "\n",
       "            pre_close    ts_code       vol  \n",
       "trade_date                                  \n",
       "2010-01-04     169.82  600519.SH  44304.88  \n",
       "2010-01-05     169.94  600519.SH  31513.18  \n",
       "2010-01-06     169.44  600519.SH  39889.03  \n",
       "2010-01-07     166.76  600519.SH  48825.55  \n",
       "2010-01-08     163.72  600519.SH  36702.09  "
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df = df.sort_index()\n",
    "df_new = df['2010':'2024']\n",
    "df_new.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "11362f54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>change</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>open</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>ts_code</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-31</th>\n",
       "      <td>753405.635</td>\n",
       "      <td>0.12</td>\n",
       "      <td>169.94</td>\n",
       "      <td>172.00</td>\n",
       "      <td>169.31</td>\n",
       "      <td>172.00</td>\n",
       "      <td>0.07</td>\n",
       "      <td>169.82</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>44304.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-02-28</th>\n",
       "      <td>499867.002</td>\n",
       "      <td>0.35</td>\n",
       "      <td>168.89</td>\n",
       "      <td>169.58</td>\n",
       "      <td>167.01</td>\n",
       "      <td>168.88</td>\n",
       "      <td>0.21</td>\n",
       "      <td>168.54</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>29655.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-03-31</th>\n",
       "      <td>361550.327</td>\n",
       "      <td>-0.60</td>\n",
       "      <td>166.24</td>\n",
       "      <td>167.45</td>\n",
       "      <td>165.99</td>\n",
       "      <td>166.45</td>\n",
       "      <td>-0.36</td>\n",
       "      <td>166.84</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>21734.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-04-30</th>\n",
       "      <td>383228.783</td>\n",
       "      <td>1.30</td>\n",
       "      <td>160.06</td>\n",
       "      <td>160.50</td>\n",
       "      <td>158.76</td>\n",
       "      <td>158.78</td>\n",
       "      <td>0.82</td>\n",
       "      <td>158.76</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>23980.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-05-31</th>\n",
       "      <td>308504.586</td>\n",
       "      <td>-0.39</td>\n",
       "      <td>128.64</td>\n",
       "      <td>129.56</td>\n",
       "      <td>126.89</td>\n",
       "      <td>127.99</td>\n",
       "      <td>-0.30</td>\n",
       "      <td>129.03</td>\n",
       "      <td>600519.SH</td>\n",
       "      <td>23975.16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                amount  change   close    high     low    open  pct_chg  \\\n",
       "trade_date                                                                \n",
       "2010-01-31  753405.635    0.12  169.94  172.00  169.31  172.00     0.07   \n",
       "2010-02-28  499867.002    0.35  168.89  169.58  167.01  168.88     0.21   \n",
       "2010-03-31  361550.327   -0.60  166.24  167.45  165.99  166.45    -0.36   \n",
       "2010-04-30  383228.783    1.30  160.06  160.50  158.76  158.78     0.82   \n",
       "2010-05-31  308504.586   -0.39  128.64  129.56  126.89  127.99    -0.30   \n",
       "\n",
       "            pre_close    ts_code       vol  \n",
       "trade_date                                  \n",
       "2010-01-31     169.82  600519.SH  44304.88  \n",
       "2010-02-28     168.54  600519.SH  29655.94  \n",
       "2010-03-31     166.84  600519.SH  21734.74  \n",
       "2010-04-30     158.76  600519.SH  23980.83  \n",
       "2010-05-31     129.03  600519.SH  23975.16  "
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_monthly = df_new.resample('M').first()\n",
    "df_monthly.head(5)\n",
    "df_new.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "29a79e8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13690045.000000002"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "const_monry = df_monthly['open'].sum()*100\n",
    "const_monry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "18b16613",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_yearly = df_new.resample('A').last()\n",
    "df_yearly = df_yearly[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "8f3a0596",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13648248.000000002"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "revc_monry = df_yearly['open'].sum()*1200\n",
    "revc_monry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "497d358a",
   "metadata": {},
   "outputs": [],
   "source": [
    "last_price = df.iloc[-1]['close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "6d9348fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "cunHuo_price = last_price * 700"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "43793d8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1026137.0"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cunHuo_price + revc_monry-const_monry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca288c8b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
